/*
 *    This file is part of SSHTunneler.
 *
 *    Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
 *
 *    SSHTunneler is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SSHTunneler is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with SSHTunneler.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package sshtunneler.library;

import java.util.ArrayList;
import java.util.List;

public class DefaultPorts {

	public static DefaultPorts inst = new DefaultPorts();
	List<DefaultPort> ports = new ArrayList<DefaultPort>();

	public List<String> get_all_port_names() {
		List<String> names = new ArrayList<String>();

		for (DefaultPort p : this.ports) {
			names.add(p.getName());
		}

		return names;
	}

	public List<DefaultPort> get_all_ports() {
		return this.ports;
	}

	public int find_port(String name) {
		for (DefaultPort p : this.ports) {
			if (p.getName().equals(name)) {
				return p.getPort();
			}
		}

		return 0;
	}

	public String find_service(int remotePort) {
		for (DefaultPort p : this.ports) {
			if (p.getPort() == remotePort) {
				return p.getName();
			}
		}

		return "";
	}

	protected DefaultPorts() {
		this.add_default_ports();
	}

	public void remove_port(DefaultPort selected) {
		this.ports.remove(selected);
	}

	public DefaultPort add_port(DefaultPort new_port) {
		this.ports.add(new_port);
		return new_port;
	}

	public DefaultPort add_port(String name, int port) {
		return this.add_port(new DefaultPort(name, port));
	}

	public void clear() {
		this.ports.clear();
	}

	private void add_default_ports() {
		this.add_port("Remote Desktop", 3389);
		this.add_port("MySQL", 3306);
		this.add_port("VNC", 5900);
		this.add_port("SSH", 22);
		this.add_port("HTTP", 80);
		this.add_port("HTTPS", 443);
		this.add_port("FileMaker", 5003);
	}
}
